
include ../Makefile.common

OBJDIR  = .obj/
DEPDIR  = .dep/
SOURCES := $(wildcard *.cc)
HEADERS := $(wildcard *.h) $(wildcard *.tcc)
OBJECTS = $(addprefix $(OBJDIR),$(SOURCES:.cc=.o))
DEPS    = $(addprefix $(DEPDIR),$(SOURCES:.cc=.d))

.PHONY : all
all: $(OBJDIR) $(DEPDIR) $(OBJECTS)
ifeq "$(SHARED)" "yes"
	$(CXX) $(CXXDYLIB) $(CXXFLAGS) -o $(DYLIB_PATH)/$(DYLIB) $(OBJDIR)*.o $(LDFLAGS)
else
	$(AR) $(DYLIB_PATH)/$(DYLIB) $(OBJDIR)*.o $(LDFLAGS)
	$(RANLIB) $(DYLIB_PATH)/$(DYLIB) 
endif
	
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif

.PHONY : install
install: $(OBJECTS)
	$(INSTALL) $(HEADERS) $(INCDIR)
	
$(OBJDIR):
	$(MKDIR) $(OBJDIR)

$(DEPDIR):
	$(MKDIR) $(DEPDIR)

$(OBJDIR)%.o: %.cc
	$(CXX) $(INCDIRS) $(CXXFLAGS) -o $@ -c $<

$(DEPDIR)%.d: %.cc $(DEPDIR)
	@$(CXX) -MM $(INCDIRS) $(CXXFLAGS) $< \
		| sed 's/$*.o/$(OBJDIR:/=\/)$*.o/g' \
	| sed 's/$*.o/& $(subst /,\/,$@)/g' > $@

.PHONY : clean
clean:
	$(RMDIR) $(OBJDIR) $(DEPDIR)
	
